//
//  DetailSheetItemView.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 17.04.25.
//

import SwiftUI

struct DetailSheetItemView : View {
    
    @State var itemType: DetailSheetItemType
    
    @Binding var item: AccountingDetailCombine
    
    var body: some View {
        HStack {
            Text(itemType.rawValue)
                .font(.system(size: 14))
                .foregroundColor(Color.koiColorTitleSecond)
            Spacer()
            if itemType == .category {
                Image(item.category.getIconAssetUri())
                    .resizable()
                    .frame(width: 18, height: 18)
            }
            Text(getItemDesc())
                .font(.system(size: 14))
                .fontWeight(.medium)
                .foregroundColor(Color.koiColorTitle)
            Image("koi_ic_arrow_right")
                .resizable()
                .frame(width: 16, height: 16)
        }
        .padding(EdgeInsets(top: 18, leading: 16, bottom: 18, trailing: 16))
    }
    
    private func getItemDesc() -> String {
        switch itemType {
        case .category:
            return item.getCategoryName()
        case .amount:
            return item.getAmountNoSign()
        case .date:
            return item.getDateText()
        case .remark:
            return item.getRemark()
        case .book:
            return item.getBookName()
        }
    }
}

enum DetailSheetItemType : String {
    case category = "类别",
         amount = "金额",
         date = "日期",
         remark = "备注",
         book = "账本"
}

@available(iOS 18, *)
#Preview {
    @Previewable @State var item: AccountingDetailCombine = AccountingDetailCombine.previewData()
    DetailSheetItemView(itemType: .category, item: $item)
}
